import static org.junit.Assert.*;

import org.junit.Test;

public class TransportSystemTest {

	@Test
	public void testLoad() {
		TransportSystem transSys = new TransportSystem();

		// test the load function for container1
		Container container1 = new Container1(50);

		transSys.load(container1, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container1, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container1, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container1, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container1, new Goods(14, GoodsType.Normal, 14));

		// container has 4 goods
		assertEquals(4, container1.getGoodsList().size());

		System.out.println("finish loading contianer1.");

		// test the load function for container2
		Container container2 = new Container2(50);

		transSys.load(container2, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container2, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container2, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container2, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container2, new Goods(14, GoodsType.Normal, 14));

		// container has 4 goods
		assertEquals(4, container2.getGoodsList().size());

		System.out.println("finish loading contianer2.");

		// test the load function for container3
		Container container3 = new Container3(50);

		transSys.load(container3, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container3, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container3, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container3, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container3, new Goods(14, GoodsType.Normal, 14));

		// container has 4 goods
		assertEquals(2, container3.getGoodsList().size());

		System.out.println("finish loading contianer3.");
	}

	@Test
	public void testUnload() {
		TransportSystem transSys = new TransportSystem();

		// test the unload function for container1
		Container container1 = new Container1(50);
		transSys.load(container1, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container1, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container1, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container1, new Goods(13, GoodsType.Frozen, 13));
		transSys.unload(container1);
		transSys.unload(container1);
		// container has 2 goods
		assertEquals(2, container1.getGoodsList().size());
		transSys.unload(container1);
		transSys.unload(container1);
		// container has 0 goods
		assertEquals(0, container1.getGoodsList().size());
		transSys.unload(container1);
		// container has 0 goods
		assertEquals(0, container1.getGoodsList().size());
		System.out.println("finish unloading contianer1.");

		// test the unload function for container2
		Container container2 = new Container2(50);
		transSys.load(container2, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container2, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container2, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container2, new Goods(13, GoodsType.Frozen, 13));
		transSys.unload(container2);
		transSys.unload(container2);
		// container has 2 goods
		assertEquals(10, container2.getGoodsList().get(0).getWeight());
		assertEquals(11, container2.getGoodsList().get(1).getWeight());
		transSys.unload(container2);
		assertEquals(10, container2.getGoodsList().get(0).getWeight());
		System.out.println("finish unloading contianer2.");

		// test the unload function for container3
		Container container3 = new Container3(50);
		transSys.load(container3, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container3, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container3, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container3, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container3, new Goods(14, GoodsType.Normal, 14));
		// container has 2 goods
		assertEquals(2, container3.getGoodsList().size());
		transSys.unload(container3);
		// container has 1 goods
		assertEquals(1, container3.getGoodsList().size());
		transSys.unload(container3);
		// container has 0 goods
		assertEquals(0, container3.getGoodsList().size());
		System.out.println("finish unloading contianer3.");
	}

	@Test
	public void testGetWeight() {
		TransportSystem transSys = new TransportSystem();

		// test the getWeight function for container1
		Container container1 = new Container1(50);
		transSys.load(container1, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container1, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container1, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container1, new Goods(13, GoodsType.Frozen, 13));
		// the 4 goods has weight 46
		assertEquals(46, transSys.getWeight(container1));
		transSys.unload(container1);
		assertEquals(36, transSys.getWeight(container1));
		transSys.unload(container1);
		assertEquals(25, transSys.getWeight(container1));
		System.out.println("finish get the weight of contianer1.");

		// test the getWeight function for container2
		Container container2 = new Container2(50);
		transSys.load(container2, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container2, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container2, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container2, new Goods(13, GoodsType.Frozen, 13));
		assertEquals(46, transSys.getWeight(container2));
		transSys.unload(container2);
		// the 4 goods has weight 46
		assertEquals(33, transSys.getWeight(container2));
		transSys.unload(container2);
		assertEquals(21, transSys.getWeight(container2));
		transSys.unload(container2);
		assertEquals(10, transSys.getWeight(container2));
		System.out.println("finish get the weight of container2.");

		// test the getWeight function for container3
		Container container3 = new Container3(50);
		transSys.load(container3, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container3, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container3, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container3, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container3, new Goods(14, GoodsType.Normal, 14));
		assertEquals(24, transSys.getWeight(container3));
		transSys.unload(container3);
		assertEquals(13, transSys.getWeight(container3));
		transSys.unload(container3);
		assertEquals(0, transSys.getWeight(container3));
		System.out.println("finish get the weight of container3.");
	}

	@Test
	public void testGetHighestValuedGoods() {
		TransportSystem transSys = new TransportSystem();
		
		// test the getHighestValuedGoods function for container1
		Container container1 = new Container1(50);
		transSys.load(container1, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container1, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container1, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container1, new Goods(13, GoodsType.Frozen, 13));
		assertEquals(13, transSys.getHighestValuedGoods(container1).getValue());
		transSys.unload(container1);
		assertEquals(13, transSys.getHighestValuedGoods(container1).getValue());
		transSys.unload(container1);
		transSys.unload(container1);
		transSys.unload(container1);
		assertEquals(null, transSys.getHighestValuedGoods(container1));
		System.out.println("finish get the weight of contianer1.");

		// test the getHighestValuedGoods function for container2
		Container container2 = new Container2(50);
		transSys.load(container2, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container2, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container2, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container2, new Goods(13, GoodsType.Frozen, 13));
		assertEquals(13, transSys.getHighestValuedGoods(container2).getValue());
		transSys.unload(container2);
		assertEquals(12, transSys.getHighestValuedGoods(container2).getValue());
		transSys.unload(container2);
		assertEquals(11, transSys.getHighestValuedGoods(container2).getValue());
		transSys.unload(container2);
		assertEquals(10, transSys.getHighestValuedGoods(container2).getValue());
		System.out.println("finish get the weight of container2.");

		// test the getHighestValuedGoods function for container3
		Container container3 = new Container3(50);
		transSys.load(container3, new Goods(10, GoodsType.Normal, 10));
		transSys.load(container3, new Goods(11, GoodsType.Frozen, 11));
		transSys.load(container3, new Goods(12, GoodsType.Normal, 12));
		transSys.load(container3, new Goods(13, GoodsType.Frozen, 13));
		transSys.load(container3, new Goods(14, GoodsType.Normal, 14));
		assertEquals(13, transSys.getHighestValuedGoods(container3).getValue());
		transSys.unload(container3);
		assertEquals(13, transSys.getHighestValuedGoods(container3).getValue());
		transSys.unload(container3);
		assertEquals(null, transSys.getHighestValuedGoods(container3));
		System.out.println("finish get the weight of container3.");
	}

}
